package messaging;

import java.net.*;
import java.util.Arrays;
import java.io.Serializable;

public class Connection implements Comparable<Connection>, Serializable
{
	InetAddress addr;
	int port;

	public Connection(InetAddress addr, int port)
	{
		this.addr = addr;
		this.port = port;
	}

	public Connection(Socket socket)
	{
		this(socket.getInetAddress(), socket.getPort());
	}
    
    public InetAddress getAddress()
    {
        return addr;
    }
    
    public int getPort()
    {
        return port;
    }
    
    public int compareTo(Connection that)
    {
        return this.toString().compareTo(that.toString());
    }

	public boolean equals(Object that)
	{
		Connection c;
		boolean result = false;

		if (that instanceof Connection)
		{
			return this.toString().equals(((Connection)that).toString());
		}
		else
		{
			return false;
		}
	}

	public String toString()
	{
		return Arrays.toString(addr.getAddress()) + ":" + port;
	}
}
